package com.doctcloud.common.shardingsphere.config;

import com.doctcloud.common.shardingsphere.strategy.DateShardingStrategy;
import com.doctcloud.common.shardingsphere.utils.ShardingKeyGenerator;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(ShardingSphereDataSource.class) // 仅当引入 shardingsphere 时生效
public class ShardingAutoConfiguration {

    // 注册日期分片策略Bean，业务模块可直接引用
    @Bean
    public DateShardingStrategy dateShardingStrategy() {
        return new DateShardingStrategy();
    }

    // 注册分片键生成工具（单例）
    @Bean
    public ShardingKeyGenerator shardingKeyGenerator() {
        return new ShardingKeyGenerator();
    }
}